<!doctype html>
<html xmlns:th="http://www.thymeleaf.org">
<head th:replace="th/include/common_head :: head(~{::title}, ~{::link}, ~{::style})">
    <title>修改工号</title>
    <link type="text/css" rel="stylesheet" th:href="@{${skinPath} + '/css.css'}"/>
    <style>
        #form1 .realname-box .form-control-feedback {
            top: 0;
            right: -85px;
        }
    </style>
</head>
<body>
<div class="container">
    <div class="row">
        <div class="col-lg-8 col-lg-offset-2">
            <div class="table-responsive">
                <form action="?op=modify" method="post" name="form1" id="form1" style="margin-top: 20px">
                    <table border="0" align="center" cellspacing="0" class="table table-bordered table-hover">
                        <tbody>
                        <tr class="active">
                            <td colspan="2" class="text-center">修改工号</td>
                        </tr>
                        <tr>
                            <td width="204" align="right">工号</td>
                            <td>
                                <div class="col-lg-9 form-inline form-group">
                                    <input name="name" id="name" class="form-control" th:value="${account.name}" readonly=""/>
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <td align="right">姓名</td>
                            <td>
                                <div class="col-lg-7 form-group realname-box">
                                    <div class="input-group">
                                        <input id="realName" name="realName" class="form-control" type="text" readonly th:value="${realName}">
                                        <span class="input-group-btn">
                                            <button class="btn btn-default" type="button" th:onclick="openWin('../userMultiSel.do?mode=single&unitCode=' + [[${unitCode}]], 800, 600)">选择</button>
                                        </span>
                                    </div>
                                    <input type="hidden" id="userName" name="userName" th:value="${account.userName}">
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2" align="center">
                                <button id="btnOk" class="btn btn-default">保存</button>
                            </td>
                        </tr>
                        </tbody>
                    </table>
                </form>
            </div>
        </div>
    </div>
</div>
</body>
<script th:inline="javascript">
    function setUsers(users, userRealNames) {
        $("#userName").val(users);
        $("#realName").val(userRealNames);
        $('#realName').trigger('change');
    }

    function getSelUserNames() {
        return $("#userName").val();
    }

    function getSelUserRealNames() {
        return $("#realName").val();
    }

    $(function () {
        $('#btnBack').click(function (e) {
            window.history.back();
            e.preventDefault();
        });

        $('#form1').bootstrapValidator({
            message: 'This value is not valid',
            excluded: [':disabled', ':hidden', ':not(:visible)'],
            // 配置校验图标
            feedbackIcons: {
                valid: 'glyphicon glyphicon-ok',    // 校验成功
                invalid: 'glyphicon glyphicon-remove',   // 校验失败
                validating: 'glyphicon glyphicon-refresh'  // 校验中
            },
            // 配置校验字段
            fields: {
                realName: {
                    validators: {
                        notEmpty: {
                            message: '用户不能为空'
                        }
                    }
                }
            }
        }).on('success.form.bv', function (e) {
            // 阻止默认的提交
            e.preventDefault();
            $.ajax({
                type: "post",
                url: "updateAccount.do",
                data: $('#form1').serialize(),
                dataType: "json",
                beforeSend: function (XMLHttpRequest) {
                    $('body').showLoading();
                },
                success: function (data, status) {
                    if (data.ret == 1) {
                        reloadTab([[${tabIdOpener}]]);
                        $.toaster({
                            "priority": "info",
                            "message": data.msg
                        });
                    } else {
                        jAlert(data.msg, [[#{prompt}]]);
                    }
                },
                complete: function (XMLHttpRequest, status) {
                    $('body').hideLoading();
                },
                error: function () {
                    //请求出错处理
                    alert(XMLHttpRequest.responseText);
                }
            });
        });
    })
</script>
</html>
